#pragma once

class Endian
{
public:

	static void WriteShortLE(char* d, short value)
	{
		d[0] = value & 0xFF;
		d[1] = (value & 0xFF00) >> 8;
	}

	static void WriteShortBE(char* d, short value)
	{
		d[1] = value & 0xFF;
		d[0] = (value & 0xFF00) >> 8;
	}

	static void WriteIntLE(char* d, int value)
	{
		d[0] = value & 0xFF;
		d[1] = (value & 0xFF00) >> 8;
		d[2] = (value & 0xFF0000) >> 16;
		d[3] = (value & 0xFF000000) >> 24;
	}

	static void WriteIntBE(char* d, int value)
	{
		d[3] = value & 0xFF;
		d[2] = (value & 0xFF00) >> 8;
		d[1] = (value & 0xFF0000) >> 16;
		d[0] = (value & 0xFF000000) >> 24;
	}

	static short ReadShortLE(char* s)
	{
		return (s[0] & 0xFF) | ((s[1] & 0xFF) << 8);
	}

	static short ReadShortBE(char* s)
	{
		return (s[1] & 0xFF) | ((s[0] & 0xFF) << 8);
	}

	static int ReadIntLE(char* s)
	{
		return (s[0] & 0xFF) | ((s[1] & 0xFF) << 8) | ((s[2] & 0xFF) << 16) | ((s[3] & 0xFF) << 24);
	}

	static int ReadIntBE(char* s)
	{
		return (s[3] & 0xFF) | ((s[2] & 0xFF) << 8) | ((s[1] & 0xFF) << 16) | ((s[0] & 0xFF) << 24);
	}
};